package com.changdu.seatunnel.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.changdu.seatunnel.admin.service.DataSourceService;

@RestController
@RequestMapping("/api/datasource")
public class DataSourceController {
    
    @Autowired
    private DataSourceService dataSourceService;
    
    @GetMapping("/instances")
    public List<String> getInstances(@RequestParam String dataCenter) {
        return dataSourceService.getInstances(dataCenter);
    }

    @GetMapping("/databases")
    public List<String> getDatabases(@RequestParam String dataCenter, @RequestParam String instance) {
        return dataSourceService.getDatabases(dataCenter, instance);
    }
    
    @GetMapping("/tables")
    public List<String> getTables(@RequestParam String dataCenter, 
                                 @RequestParam String instance,
                                 @RequestParam String database) {
    	return dataSourceService.getTables(dataCenter, instance, database);
    }

    @GetMapping("/fields")
    public Object getTableFields(@RequestParam String dataCenter, @RequestParam String instance, @RequestParam String database, 
            @RequestParam String tableName) {
    	return dataSourceService.getTableStructure(dataCenter, instance, database, tableName);
    }
    
    /**
     * 清空缓存
     */
    @GetMapping("/cleanCache")
    public void cleanCache() {
    	dataSourceService.cleanCached();
    }    
} 